home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / CGRAPH_S.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  7.7 KB  |  233 lines

  1. package sub_arctic.lib;
  2.  
  3. import sub_arctic.output.drawable;
  4. import sub_arctic.constraints.std_encoding_consts;
  5. import sub_arctic.constraints.std_constraint_impl;
  6. import sub_arctic.lib.manager;
  7. import sub_arctic.lib.sub_arctic_error;
  8. import java.awt.Rectangle;
  9. import java.awt.Point;
  10. import java.awt.Font;
  11. import java.awt.FontMetrics;
  12. import java.awt.Color;
  13. import java.util.Vector;
  14.  
  15. /** 
  16.  * An interface_pred predicate class that performs a semantic redraw action
  17.  * for a semantic lens.  In this case the object draws debugging information
  18.  * about the constraint dependency graph of each object (along with a class
  19.  * name tag and bounding box). This predicate expects a sem_draw_context 
  20.  * object as its parameters argument.  This predicate is executed for its 
  21.  * side effect only and always returns false.
  22.  *
  23.  * @see sub_arctic.lib.base_interactor#traverse_and_collect
  24.  * @author Scott Hudson
  25.  */
  26. public class cgraph_sem_draw extends nametag_sem_draw 
  27. implements interactor_pred, interactor_consts{
  28.  
  29.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  30.  
  31.   /** Unique id for this drawing traversal */
  32.   public static final int id = manager.unique_int();
  33.  
  34.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  35.  
  36.   /** 
  37.    * Full constructor. 
  38.    * @param Font fnt the font to draw tags in. 
  39.    * @param Color c the color to draw tags and borders in.
  40.    */
  41.   public cgraph_sem_draw(Font fnt, Color c)
  42.     {
  43.       /* establish color */
  44.       set_tag_color(c);
  45.  
  46.       /* establish font and metrics object */
  47.       set_font(fnt);
  48.     }
  49.  
  50.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  51.  
  52.   /** Constructor using default font and tag color. */
  53.   public cgraph_sem_draw()
  54.     {
  55.       /* use already initialized font to also set up metrics object */
  56.       set_font(_font);
  57.     }
  58.  
  59.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  60.  
  61.   /** 
  62.    * Perform the predicate test.
  63.    * 
  64.    * @param obj        the interactor the predicate is drawing.
  65.    * @param parameters a sem_draw_context object containing the a drawable 
  66.    *                   object and other bookkeeping needed for drawing.
  67.    * @return false in all cases.
  68.    */
  69.   public boolean test(interactor obj, Object parameters) 
  70. {
  71.       sem_draw_context context;
  72.       String           tag;
  73.       Rectangle        bound;
  74.       int              sz_w, sz_h, last_dot;
  75.       int              wv, hv;
  76.  
  77.       /* type check the parameters */
  78.       if (!(parameters instanceof sem_draw_context))
  79.     throw new sub_arctic_error("Non-sem_draw_context object passed as parameter");
  80.  
  81.       /* don't draw semantic lens or semantic lens parent objects */
  82.       if (obj instanceof semantic_lens || obj instanceof semantic_lens_parent) 
  83.         return false;
  84.  
  85.       /* let superclass draw tag and bounding box */
  86.       super.test(obj, parameters);
  87.  
  88.       /* extract drawing context */
  89.       context = (sem_draw_context)parameters;
  90.  
  91.       /* extract object size then draw dependency edges for each constraint */
  92.       wv = obj.w(); 
  93.       hv = obj.h();
  94.  
  95.       /* draw x constraint edges */
  96.       draw_constraint(context.surface, obj, obj.x_constraint().encoding(), 
  97.                  std_encoding_consts.HORIZONTAL, 0, hv/4);
  98.  
  99.       /* y constraint edges */
  100.       draw_constraint(context.surface, obj, obj.y_constraint().encoding(), 
  101.                  std_encoding_consts.VERTICAL, wv/4, 0);
  102.  
  103.       /* w constraint edges */
  104.       draw_constraint(context.surface, obj, obj.w_constraint().encoding(), 
  105.                  std_encoding_consts.HORIZONTAL, wv, hv*3/4);
  106.  
  107.       /* h constraint edges */
  108.       draw_constraint(context.surface, obj, obj.h_constraint().encoding(), 
  109.                  std_encoding_consts.VERTICAL, wv*3/4, hv);
  110.  
  111.       /* draw visible constraint edges */
  112.       draw_constraint(context.surface, obj, obj.visible_constraint().encoding(),
  113.                  std_encoding_consts.VERTICAL, 0, 0);
  114.  
  115.       /* draw enabled constraint edges */
  116.       draw_constraint(context.surface, obj, obj.enabled_constraint().encoding(),
  117.                  std_encoding_consts.VERTICAL, 0, 0);
  118.  
  119.       /* draw part_a constraint edges */
  120.       draw_constraint(context.surface, obj, obj.part_a_constraint().encoding(),
  121.                  std_encoding_consts.VERTICAL, wv/2, hv/2);
  122.  
  123.       /* draw part_B constraint edges */
  124.       draw_constraint(context.surface, obj, obj.part_b_constraint().encoding(),
  125.                  std_encoding_consts.VERTICAL, wv/2, hv/2);
  126.  
  127.  
  128.       /* don't actually add the object to the result collection */
  129.       return false;
  130.     }
  131.    //had:
  132.    //* @exception sub_arctic.exception.bad_value thrown if the parameters 
  133.    //*    argument is not a sem_draw_context object.
  134.  
  135.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  136.  
  137.   /**
  138.    * Draw the dependency lines for a given encoded constraint (which is attached
  139.    * to the given object and uses the given orientation). The lines start at
  140.    * locations indicated by the dependencies of the encoded constraint, and 
  141.    * end at the given position.<p>
  142.    *
  143.    * @param drawable   surf    where the drawing takes place
  144.    * @param interactor obj     object the constraint is attached to (hence where   *                           dependencies are relative to).
  145.    * @param int        enc     encoding of the constraint.
  146.    * @param int        orient  orientation of the constraint.
  147.    * @param int        xpos    x position of edge end points
  148.    * @param int        ypos    y position of edge end points
  149.    */
  150.   protected void draw_constraint(drawable surf, interactor obj, int enc, 
  151.     int orient, int xpos, int ypos)
  152.     {
  153.       Vector     dep_list = null;
  154.       int        i, from_part;
  155.       interactor from_obj;
  156.       Point      f_pt;
  157.       int        from_x = 0;
  158.       int        from_y = 0;
  159.  
  160.       /* get the dependency edge list for the encoded constraint */
  161.       dep_list = std_constraint_impl.the_impl().depend_list(enc, obj, orient);
  162.  
  163.       /* draw one edge for each entry (each pair) in dependency list */
  164.       for (i = 0; i < dep_list.size(); i += 2)
  165.     {
  166.       /* pull out the object and part within it */
  167.       from_obj = (interactor)dep_list.elementAt(i);
  168.       from_part = ((Integer)dep_list.elementAt(i+1)).intValue();
  169.  
  170.       /* draw from position corresponding to the part */
  171.       switch(from_part)
  172.         {
  173.           case X:
  174.         from_x = 0;
  175.         from_y = from_obj.h()/4;
  176.           break;
  177.           case Y:
  178.         from_x = from_obj.w()/4;
  179.         from_y = 0;
  180.           break;
  181.           case W:
  182.         from_x = from_obj.w();
  183.         from_y = from_obj.h()*3/4;
  184.           break;
  185.           case H:
  186.         from_x = from_obj.w()*3/4;
  187.         from_y = from_obj.h();
  188.           break;
  189.           case VISIBLE:
  190.         from_x = 0;
  191.         from_y = 0;
  192.           break;
  193.           case ENABLED:
  194.         from_x = 0;
  195.         from_y = 0;
  196.           break;
  197.           case PART_A:
  198.         from_x = from_obj.w()/2;
  199.         from_y = from_obj.h()/2;
  200.           break;
  201.           case PART_B:
  202.         from_x = from_obj.w()/2;
  203.         from_y = from_obj.h()/2;
  204.           break;
  205.         }
  206.  
  207.       /* put from_x, from_y into local coordinates of obj */
  208.       f_pt = obj.global_to_local(from_obj.local_to_global(from_x, from_y));
  209.  
  210.       /* draw the arrow */
  211.       surf.draw_line(f_pt.x, f_pt.y, xpos, ypos);
  212.       surf.fill_arrowhead(f_pt.x, f_pt.y, xpos, ypos);
  213.     }
  214.     }
  215.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  216. };
  217. /*=========================== COPYRIGHT NOTICE ===========================
  218.  
  219. This file is part of the subArctic user interface toolkit.
  220.  
  221. Copyright (c) 1996 Scott Hudson and Ian Smith
  222. All rights reserved.
  223.  
  224. The subArctic system is freely available for most uses under the terms
  225. and conditions described in 
  226.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  227. and appearing in full in the lib/interactor.java source file.
  228.  
  229. The current release and additional information about this software can be 
  230. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  231.  
  232. ========================================================================*/
  233.